package booksys.defer;

import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Dao数据访问接口对象
 * mybatis的映射器mappers，实现数据库与java object对应
 */
@Mapper//此注解说明本接口是mybatis的映射器，更快定位
public interface DeferDao {
    //javabean必须写对应属性名
    @Select("select bd_id,st_name,bookdefer.bob_id,bookdefer.bb_id,bd_extime,bd_defer,bd_time,bd_agree from bookdefer,student,bookborrow where bookdefer.ma_id=#{userId} and bd_agree=0 and student.st_id=bookdefer.st_id and bookborrow.bob_id=bookdefer.bob_id order by bd_id desc")
    List<Bookdefer> findNewBookdeferList(String userId);

    @Update("update bookdefer set bd_agree = 1 where bd_id=#{bd_id}")
    void permitBookdefer(Integer bd_id);

    @Update("update bookborrow set bb_extime=#{bd_defer} where bob_id=#{bob_id}")
    void updatebbExtime(DeferDto dto);

    @Update("update bookdefer set bd_extime=#{bd_defer} where bd_id=#{bd_id}")
    void updatebdExtime(DeferDto dto);

    @Update("update bookdefer set bd_agree = 2,bd_up=0 where bd_id=#{bd_id}")
    void banBookdefer(Integer bd_id);

    @Select("select bd_id,st_name,bookdefer.bob_id,bookdefer.bb_id,bd_extime,bd_defer,bd_time,bd_agree from bookdefer,student,bookborrow where bookdefer.ma_id=#{userId} and bd_agree!=0 and student.st_id=bookdefer.st_id and bookborrow.bob_id=bookdefer.bob_id order by bd_id desc")
    List<Bookdefer> findHistBookdeferList(String userId);
}
